/*
** ############################################################################
**     Project   : osdee - Operative Systems Design for Embedded Envrionments
**     File      : main.h
**     Revision  ; 1.0
**     Abstract  :
**         Main Function Definition.
**     Processor : MC9S12XEP100CVL
**     Version   : Component 01.042, Driver 01.05, CPU db: 3.00.036
**               : Program compiled with CW for HCS12(X) v5.0, tested on DEMO9S12XEP100 board
**     Datasheet : MC9S12XEP100 Rev. 1.19 12/2008
**
**     Copyright : 2014 Fernando Rodriguez, Open source with out any responsability.
**     
**     mail      : frr@gmail.com
** ############################################################################
*/

#include "main.h"

void main(void) 
{    
  /* General Device Initialization */
  Mcu_init();
  
  /* Initialize Memory Alloc Functions */  
  vfnMemAlloc_NearInit(NearMemAlloc_config);
  
  /* Initialize Interrupt Module */
  Mcu_vInterrupt_Init();
  
  INTERRUPT_DISABLE();
            
  /* PLL initialization to preconfigured frequency */
  Mcu_vPLL_Init();
  
  /* Initialize GPT Module */
  Gpt_Init(&mal_mcu_tGPT_configuration);

  /* Initialize OS Functions */
  OS_Init(TaskConfig);  
  
  /* Temporal port initializations for testing, they should be in the io layer*/
  DDRA = 0xff; // initialize all PTA as output
  PORTA = 0x0; // initialize PTA to 0
  
  DDRB = 0xff; // initialize all PTB as output
  PORTB = 0x0; // initialize PTB to 0
  
  /* Initialize Scheduler*/
  SchM_Init(TaskConfig);
  SchM_Start();
  INTERRUPT_ENABLE(); 
  asm{
      leas -0x1F,sp
  };
    
  for(;;) {
    /* _FEED_COP(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
  } /* loop forever */
  /* please make sure that you never leave main */
}
